<?php
session_start(); // Initialize Session data
ob_start(); // Turn on output buffering
?>
<?php include "ewcfg7.php" ?>
<?php include "ewmysql7.php" ?>
<?php include "phpfn7.php" ?>
<?php include "psacar_carinfo.php" ?>
<?php include "psacar_car_imageinfo.php" ?>
<?php include "psacar_userinfo.php" ?>
<?php include "userfn7.php" ?>
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Always modified
header("Cache-Control: private, no-store, no-cache, must-revalidate"); // HTTP/1.1 
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
?>
<?php

// Create page object
$psacar_car_add = new cpsacar_car_add();
$Page =& $psacar_car_add;

// Page init
$psacar_car_add->Page_Init();

// Page main
$psacar_car_add->Page_Main();
?>
<?php include "header.php" ?>
<script type="text/javascript">
<!--

// Create page object
var psacar_car_add = new ew_Page("psacar_car_add");

// page properties
psacar_car_add.PageID = "add"; // page ID
psacar_car_add.FormID = "fpsacar_caradd"; // form ID
var EW_PAGE_ID = psacar_car_add.PageID; // for backward compatibility

// extend page with ValidateForm function
psacar_car_add.ValidateForm = function(fobj) {    
	ew_PostAutoSuggest(fobj);
	if (!this.ValidateRequired)
		return true; // ignore validation
	if (fobj.a_confirm && fobj.a_confirm.value == "F")
		return true;
	var i, elm, aelm, infix;
	var rowcnt = (fobj.key_count) ? Number(fobj.key_count.value) : 1;
	for (i=0; i<rowcnt; i++) {
		infix = (fobj.key_count) ? String(i+1) : "";
		elm = fobj.elements["x" + infix + "_dealer_id"];
		if (elm && !ew_HasValue(elm))
			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($psacar_car->dealer_id->FldCaption()) ?>");
		elm = fobj.elements["x" + infix + "_model_id"];
		if (elm && !ew_HasValue(elm))
			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($psacar_car->model_id->FldCaption()) ?>");
		elm = fobj.elements["x" + infix + "_year"];
		if (elm && !ew_HasValue(elm))
			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($psacar_car->year->FldCaption()) ?>");
		elm = fobj.elements["x" + infix + "_external_color_id"];
		if (elm && !ew_HasValue(elm))
                    return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($psacar_car->external_color_id->FldCaption()) ?>");
		elm = fobj.elements["x" + infix + "_internal_color_id"];
		if (elm && !ew_HasValue(elm))
			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($psacar_car->internal_color_id->FldCaption()) ?>");
		elm = fobj.elements["x" + infix + "_type_id"];
		if (elm && !ew_HasValue(elm))
                    return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($psacar_car->type_id->FldCaption()) ?>");
		elm = fobj.elements["x" + infix + "_category_id"];
		if (elm && !ew_HasValue(elm))
			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($psacar_car->category_id->FldCaption()) ?>");
                    
		elm = fobj.elements["x" + infix + "_year"];
		if (elm && !ew_CheckNumber(elm.value))
                    return ew_OnError(this, elm, "<?php echo ew_JsEncode2($psacar_car->year->FldErrMsg()) ?>");
		elm = fobj.elements["x" + infix + "_price"];
		if (elm && !ew_CheckNumber(elm.value))
			return ew_OnError(this, elm, "<?php echo ew_JsEncode2($psacar_car->price->FldErrMsg()) ?>");
		elm = fobj.elements["x" + infix + "_quality"];
		if (elm && !ew_CheckInteger(elm.value))
			return ew_OnError(this, elm, "<?php echo ew_JsEncode2($psacar_car->quality->FldErrMsg()) ?>");
		elm = fobj.elements["x" + infix + "_post_date"];
		if (elm && !ew_CheckDate(elm.value))
                    return ew_OnError(this, elm, "<?php echo ew_JsEncode2($psacar_car->post_date->FldErrMsg()) ?>");
		elm = fobj.elements["x" + infix + "_expiration_date"];
		if (elm && !ew_CheckDate(elm.value))
			return ew_OnError(this, elm, "<?php echo ew_JsEncode2($psacar_car->expiration_date->FldErrMsg()) ?>");

		// Call Form Custom Validate event
		if (!this.Form_CustomValidate(fobj)) return false;
	}
	return true;
}

// extend page with Form_CustomValidate function
psacar_car_add.Form_CustomValidate =  
 function(fobj) { // DO NOT CHANGE THIS LINE!

 	// Your custom validation code here, return false if invalid. 
 	return true;
 }
<?php if (EW_CLIENT_VALIDATE) { ?>
psacar_car_add.ValidateRequired = true; // uses JavaScript validation
<?php } else { ?>
psacar_car_add.ValidateRequired = false; // no JavaScript validation
<?php } ?>

//-->
</script>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script type="text/javascript">
<!--
_width_multiplier = 20;
_height_multiplier = 60;
var ew_DHTMLEditors = [];

// update value from editor to textarea
function ew_UpdateTextArea() {
	if (typeof ew_DHTMLEditors != 'undefined' && typeof CKEDITOR != 'undefined') {			
		var inst;			
		for (inst in CKEDITOR.instances)
			CKEDITOR.instances[inst].updateElement();
	}
}

// update value from textarea to editor
function ew_UpdateDHTMLEditor(name) {
	if (typeof ew_DHTMLEditors != 'undefined' && typeof CKEDITOR != 'undefined') {
		var inst = CKEDITOR.instances[name];		
		if (inst)
			inst.setData(inst.element.value);
	}
}

// focus editor
function ew_FocusDHTMLEditor(name) {
	if (typeof ew_DHTMLEditors != 'undefined' && typeof CKEDITOR != 'undefined') {
		var inst = CKEDITOR.instances[name];	
		if (inst)
			inst.focus();
	}
}

//-->
</script>
<link rel="stylesheet" type="text/css" media="all" href="calendar/calendar-win2k-cold-1.css" title="win2k-1">
<script type="text/javascript" src="calendar/calendar.js"></script>
<script type="text/javascript" src="calendar/lang/calendar-en.js"></script>
<script type="text/javascript" src="calendar/calendar-setup.js"></script>
<script language="JavaScript" type="text/javascript">
<!--

// Write your client script here, no need to add script tags.
// To include another .js script, use:
// ew_ClientScriptInclude("my_javascript.js"); 
//-->

</script>
<p><span class="phpmaker"><?php echo $Language->Phrase("Add") ?>&nbsp;<?php echo $Language->Phrase("TblTypeTABLE") ?><?php echo $psacar_car->TableCaption() ?><br><br>
<a href="<?php echo $psacar_car->getReturnUrl() ?>"><?php echo $Language->Phrase("GoBack") ?></a></span></p>
<?php
if (EW_DEBUG_ENABLED)
	echo ew_DebugMsg();
$psacar_car_add->ShowMessage();
?>
<form name="fpsacar_caradd" id="fpsacar_caradd" action="<?php echo ew_CurrentPage() ?>" method="post" enctype="multipart/form-data" onsubmit="return psacar_car_add.ValidateForm(this);">
<p>
<input type="hidden" name="t" id="t" value="psacar_car">
<input type="hidden" name="a_add" id="a_add" value="A">
<table cellspacing="0" class="ewGrid"><tr><td class="ewGridContent">
<div class="ewGridMiddlePanel">
<table cellspacing="0" class="ewTable">
<?php if ($psacar_car->dealer_id->Visible) { // dealer_id ?>
	<tr<?php echo $psacar_car->dealer_id->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_car->dealer_id->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $psacar_car->dealer_id->CellAttributes() ?>><span id="el_dealer_id">
<select id="x_dealer_id" name="x_dealer_id" title="<?php echo $psacar_car->dealer_id->FldTitle() ?>"<?php echo $psacar_car->dealer_id->EditAttributes() ?>>
<?php
if (is_array($psacar_car->dealer_id->EditValue)) {
	$arwrk = $psacar_car->dealer_id->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($psacar_car->dealer_id->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
</span><?php echo $psacar_car->dealer_id->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_car->model_id->Visible) { // model_id ?>
	<tr<?php echo $psacar_car->model_id->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_car->model_id->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $psacar_car->model_id->CellAttributes() ?>><span id="el_model_id">
<select id="x_model_id" name="x_model_id" title="<?php echo $psacar_car->model_id->FldTitle() ?>"<?php echo $psacar_car->model_id->EditAttributes() ?>>
<?php
if (is_array($psacar_car->model_id->EditValue)) {
	$arwrk = $psacar_car->model_id->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($psacar_car->model_id->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
</span><?php echo $psacar_car->model_id->CustomMsg ?></td>
	</tr>
<?php } ?> 
<?php if ($psacar_car->year->Visible) { // year ?>
	<tr<?php echo $psacar_car->year->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_car->year->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $psacar_car->year->CellAttributes() ?>><span id="el_year">
<input type="text" name="x_year" id="x_year" title="<?php echo $psacar_car->year->FldTitle() ?>" size="30" value="<?php echo $psacar_car->year->EditValue ?>"<?php echo $psacar_car->year->EditAttributes() ?>>
</span><?php echo $psacar_car->year->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_car->external_color_id->Visible) { // internal_color_id ?>
	<tr<?php echo $psacar_car->external_color_id->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_car->external_color_id->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $psacar_car->external_color_id->CellAttributes() ?>><span id="el_external_color_id">
<select id="x_external_color_id" name="x_external_color_id" title="<?php echo $psacar_car->external_color_id->FldTitle() ?>"<?php echo $psacar_car->external_color_id->EditAttributes() ?>>
<?php
if (is_array($psacar_car->external_color_id->EditValue)) {
	$arwrk = $psacar_car->external_color_id->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($psacar_car->external_color_id->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
</span><?php echo $psacar_car->internal_color_id->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_car->internal_color_id->Visible) { // internal_color_id ?>
	<tr<?php echo $psacar_car->internal_color_id->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_car->internal_color_id->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $psacar_car->internal_color_id->CellAttributes() ?>><span id="el_internal_color_id">
<select id="x_internal_color_id" name="x_internal_color_id" title="<?php echo $psacar_car->internal_color_id->FldTitle() ?>"<?php echo $psacar_car->internal_color_id->EditAttributes() ?>>
<?php
if (is_array($psacar_car->internal_color_id->EditValue)) {
	$arwrk = $psacar_car->internal_color_id->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($psacar_car->internal_color_id->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
</span><?php echo $psacar_car->internal_color_id->CustomMsg ?></td>
	</tr>
<?php } ?>        
<?php if ($psacar_car->category_id->Visible) { // category_id ?>
	<tr<?php echo $psacar_car->category_id->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_car->category_id->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $psacar_car->category_id->CellAttributes() ?>><span id="el_category_id">
<select id="x_category_id" name="x_category_id" title="<?php echo $psacar_car->category_id->FldTitle() ?>"<?php echo $psacar_car->category_id->EditAttributes() ?>>
<?php
if (is_array($psacar_car->category_id->EditValue)) {
	$arwrk = $psacar_car->category_id->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($psacar_car->category_id->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
</span><?php echo $psacar_car->category_id->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_car->type_id->Visible) { // type_id ?>
	<tr<?php echo $psacar_car->type_id->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_car->type_id->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $psacar_car->type_id->CellAttributes() ?>><span id="el_type_id">
<select id="x_type_id" name="x_type_id" title="<?php echo $psacar_car->type_id->FldTitle() ?>"<?php echo $psacar_car->type_id->EditAttributes() ?>>
<?php
if (is_array($psacar_car->type_id->EditValue)) {
	$arwrk = $psacar_car->type_id->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($psacar_car->type_id->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
</span><?php echo $psacar_car->type_id->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php 
if ($psacar_car->vehicle_id_number->Visible) { // vehicle_id_number ?>
    <tr<?php echo $psacar_car->vehicle_id_number->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_car->vehicle_id_number->FldCaption() ?></td>
		<td<?php echo $psacar_car->vehicle_id_number->CellAttributes() ?>><span id="el_vehicle_id_number">
    <input type="text" name="x_vehicle_id_number" id="x_vehicle_id_number" title="<?php echo $psacar_car->vehicle_id_number->FldTitle() ?>" size="30" maxlength="255" value="<?php echo $psacar_car->vehicle_id_number->EditValue ?>"<?php echo $psacar_car->vehicle_id_number->EditAttributes() ?>>
</span><?php echo $psacar_car->vehicle_id_number->CustomMsg ?></td>
	</tr>
<?php 
}
?>        
<?php if ($psacar_car->description->Visible) { // description ?>
	<tr<?php echo $psacar_car->description->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_car->description->FldCaption() ?></td>
		<td<?php echo $psacar_car->description->CellAttributes() ?>><span id="el_description">
<textarea name="x_description" id="x_description" title="<?php echo $psacar_car->description->FldTitle() ?>" cols="40" rows="10"<?php echo $psacar_car->description->EditAttributes() ?>><?php echo $psacar_car->description->EditValue ?></textarea>
<script type="text/javascript">
<!--
ew_DHTMLEditors.push(new ew_DHTMLEditor("x_description", function() {
	var oCKeditor = CKEDITOR.replace('x_description', { width: 40*_width_multiplier, height: 10*_height_multiplier, autoUpdateElement: false, baseHref: 'ckeditor/'});
	this.active = true;
}));
-->
</script>
</span><?php echo $psacar_car->description->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_car->price->Visible) { // price ?>
	<tr<?php echo $psacar_car->price->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_car->price->FldCaption() ?></td>
		<td<?php echo $psacar_car->price->CellAttributes() ?>><span id="el_price">
<input type="text" name="x_price" id="x_price" title="<?php echo $psacar_car->price->FldTitle() ?>" size="30" value="<?php echo $psacar_car->price->EditValue ?>"<?php echo $psacar_car->price->EditAttributes() ?>>
</span><?php echo $psacar_car->price->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_car->quality->Visible) { // quality ?>
	<tr<?php echo $psacar_car->quality->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_car->quality->FldCaption() ?></td>
		<td<?php echo $psacar_car->quality->CellAttributes() ?>><span id="el_quality">
<div id="as_x_quality" style="z-index: 8910">
	<input type="text" name="sv_x_quality" id="sv_x_quality" value="<?php echo $psacar_car->quality->EditValue ?>" title="<?php echo $psacar_car->quality->FldTitle() ?>" size="30"<?php echo $psacar_car->quality->EditAttributes() ?>>&nbsp;<span id="em_x_quality" class="ewMessage" style="display: none"><?php echo $Language->Phrase("UnmatchedValue") ?></span>
	<div id="sc_x_quality"></div>
</div>
<input type="hidden" name="x_quality" id="x_quality" value="<?php echo $psacar_car->quality->CurrentValue ?>">
<?php
$sSqlWrk = "SELECT `code`, `mileage` FROM `psacar_mileage`";
$sWhereWrk = "`mileage` LIKE '{query_value}%'";
if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
	$sSqlWrk = TEAencrypt($sSqlWrk, EW_RANDOM_KEY);
?>
<input type="hidden" name="s_x_quality" id="s_x_quality" value="<?php echo $sSqlWrk ?>">
<script type="text/javascript">
<!--
var oas_x_quality = new ew_AutoSuggest("sv_x_quality", "sc_x_quality", "s_x_quality", "em_x_quality", "x_quality", "", false);
oas_x_quality.formatResult = function(ar) {	
	var df1 = ar[1];
	return df1;
};
oas_x_quality.ac.typeAhead = false;

//-->
</script>
</span><?php echo $psacar_car->quality->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_car->transmission->Visible) { // transmission ?>
	<tr<?php echo $psacar_car->transmission->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_car->transmission->FldCaption() ?></td>
		<td<?php echo $psacar_car->transmission->CellAttributes() ?>><span id="el_transmission">
<select id="x_transmission" name="x_transmission" title="<?php echo $psacar_car->transmission->FldTitle() ?>"<?php echo $psacar_car->transmission->EditAttributes() ?>>
<?php
if (is_array($psacar_car->transmission->EditValue)) {
	$arwrk = $psacar_car->transmission->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($psacar_car->transmission->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
</span><?php echo $psacar_car->transmission->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_car->drive_train->Visible) { // drive_train ?>
	<tr<?php echo $psacar_car->drive_train->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_car->drive_train->FldCaption() ?></td>
		<td<?php echo $psacar_car->drive_train->CellAttributes() ?>><span id="el_drive_train">
<select id="x_drive_train" name="x_drive_train" title="<?php echo $psacar_car->drive_train->FldTitle() ?>"<?php echo $psacar_car->drive_train->EditAttributes() ?>>
<?php
if (is_array($psacar_car->drive_train->EditValue)) {
	$arwrk = $psacar_car->drive_train->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($psacar_car->drive_train->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
</span><?php echo $psacar_car->drive_train->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_car->door_count->Visible) { // door_count ?>
	<tr<?php echo $psacar_car->door_count->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_car->door_count->FldCaption() ?></td>
		<td<?php echo $psacar_car->door_count->CellAttributes() ?>><span id="el_door_count">
<select id="x_door_count" name="x_door_count" title="<?php echo $psacar_car->door_count->FldTitle() ?>"<?php echo $psacar_car->door_count->EditAttributes() ?>>
<?php
if (is_array($psacar_car->door_count->EditValue)) {
	$arwrk = $psacar_car->door_count->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($psacar_car->door_count->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
</span><?php echo $psacar_car->door_count->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_car->fuel->Visible) { // fuel ?>
	<tr<?php echo $psacar_car->fuel->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_car->fuel->FldCaption() ?></td>
		<td<?php echo $psacar_car->fuel->CellAttributes() ?>><span id="el_fuel">
<div id="tp_x_fuel" class="<?php echo EW_ITEM_TEMPLATE_CLASSNAME; ?>"><input type="checkbox" name="x_fuel[]" id="x_fuel[]" title="<?php echo $psacar_car->fuel->FldTitle() ?>" value="{value}"<?php echo $psacar_car->fuel->EditAttributes() ?>></div>
<div id="dsl_x_fuel" repeatcolumn="5">
<?php
$arwrk = $psacar_car->fuel->EditValue;
if (is_array($arwrk)) {
	$armultiwrk= explode(",", strval($psacar_car->fuel->CurrentValue));
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = "";
		for ($ari = 0; $ari < count($armultiwrk); $ari++) {
			if (strval($arwrk[$rowcntwrk][0]) == trim(strval($armultiwrk[$ari]))) {
				$selwrk = " checked=\"checked\"";
				if ($selwrk <> "") $emptywrk = FALSE;
				break;
			}
		}

		// Note: No spacing within the LABEL tag
?>
<?php echo ew_RepeatColumnTable($rowswrk, $rowcntwrk, 5, 1) ?>
<label><input type="checkbox" name="x_fuel[]" id="x_fuel[]" title="<?php echo $psacar_car->fuel->FldTitle() ?>" value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?><?php echo $psacar_car->fuel->EditAttributes() ?>><?php echo $arwrk[$rowcntwrk][1] ?></label>
<?php echo ew_RepeatColumnTable($rowswrk, $rowcntwrk, 5, 2) ?>
<?php
	}
}
?>
</div>
</span><?php echo $psacar_car->fuel->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_car->status->Visible) { // status ?>
	<tr<?php echo $psacar_car->status->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_car->status->FldCaption() ?></td>
		<td<?php echo $psacar_car->status->CellAttributes() ?>><span id="el_status">
<select id="x_status" name="x_status" title="<?php echo $psacar_car->status->FldTitle() ?>"<?php echo $psacar_car->status->EditAttributes() ?>>
<?php
if (is_array($psacar_car->status->EditValue)) {
	$arwrk = $psacar_car->status->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($psacar_car->status->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
</span><?php echo $psacar_car->status->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_car->post_date->Visible) { // post_date ?>
	<tr<?php echo $psacar_car->post_date->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_car->post_date->FldCaption() ?></td>
		<td<?php echo $psacar_car->post_date->CellAttributes() ?>><span id="el_post_date">
<input type="text" name="x_post_date" id="x_post_date" title="<?php echo $psacar_car->post_date->FldTitle() ?>" value="<?php echo $psacar_car->post_date->EditValue ?>"<?php echo $psacar_car->post_date->EditAttributes() ?>>
&nbsp;<img src="images/calendar.png" id="cal_x_post_date" name="cal_x_post_date" alt="<?php echo $Language->Phrase("PickDate") ?>" title="<?php echo $Language->Phrase("PickDate") ?>" style="cursor:pointer;cursor:hand;">
<script type="text/javascript">
Calendar.setup({
	inputField: "x_post_date", // input field id
	ifFormat: "%Y/%m/%d", // date format
	button: "cal_x_post_date" // button id
});
</script>
</span><?php echo $psacar_car->post_date->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_car->expiration_date->Visible) { // expiration_date ?>
	<tr<?php echo $psacar_car->expiration_date->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_car->expiration_date->FldCaption() ?></td>
		<td<?php echo $psacar_car->expiration_date->CellAttributes() ?>><span id="el_expiration_date">
<input type="text" name="x_expiration_date" id="x_expiration_date" title="<?php echo $psacar_car->expiration_date->FldTitle() ?>" value="<?php echo $psacar_car->expiration_date->EditValue ?>"<?php echo $psacar_car->expiration_date->EditAttributes() ?>>
&nbsp;<img src="images/calendar.png" id="cal_x_expiration_date" name="cal_x_expiration_date" alt="<?php echo $Language->Phrase("PickDate") ?>" title="<?php echo $Language->Phrase("PickDate") ?>" style="cursor:pointer;cursor:hand;">
<script type="text/javascript">
Calendar.setup({
	inputField: "x_expiration_date", // input field id
	ifFormat: "%Y/%m/%d", // date format
	button: "cal_x_expiration_date" // button id
});
</script>
</span><?php echo $psacar_car->expiration_date->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php 
if ($psacar_car->image_1->Visible) { // image 
?>
    <tr<?php echo $psacar_car->image_1->RowAttributes ?>>
        <td class="ewTableHeader">
<?php 
            echo $psacar_car->image_1->FldCaption()
?>
        </td>
        <td<?php echo $psacar_car->image_1->CellAttributes() ?>>
            <span id="el_image">
                <input 
                    type="file" 
                    name="x_image_1" 
                    id="x_image_1" 
                    title="<?php echo $psacar_car->image_1->FldTitle() ?>" 
                    size="30"<?php echo $psacar_car->image_1->EditAttributes() ?>>
            </span>
<?php 
                echo $psacar_car->image_1->CustomMsg 
?>
        </td>
    </tr>
<?php 
} 
?>
<?php 
if ($psacar_car->image_2->Visible) { // image 
?>
    <tr<?php echo $psacar_car->image_2->RowAttributes ?>>
        <td class="ewTableHeader">
<?php 
            echo $psacar_car->image_2->FldCaption()
?>
        </td>
        <td<?php echo $psacar_car->image_2->CellAttributes() ?>>
            <span id="el_image">
                <input 
                    type="file" 
                    name="x_image_2" 
                    id="x_image_2" 
                    title="<?php echo $psacar_car->image_2->FldTitle() ?>" 
                    size="30"<?php echo $psacar_car->image_2->EditAttributes() ?>>
            </span>
<?php 
                echo $psacar_car->image_2->CustomMsg 
?>
        </td>
    </tr>
<?php 
} 
?> 
<?php 
if ($psacar_car->image_3->Visible) { // image 
?>
    <tr<?php echo $psacar_car->image_3->RowAttributes ?>>
        <td class="ewTableHeader">
<?php 
            echo $psacar_car->image_3->FldCaption()
?>
        </td>
        <td<?php echo $psacar_car->image_3->CellAttributes() ?>>
            <span id="el_image">
                <input 
                    type="file" 
                    name="x_image_3" 
                    id="x_image_3" 
                    title="<?php echo $psacar_car->image_3->FldTitle() ?>" 
                    size="30"<?php echo $psacar_car->image_3->EditAttributes() ?>>
            </span>
<?php 
                echo $psacar_car->image_3->CustomMsg 
?>
        </td>
    </tr>
<?php 
} 
?>
<?php 
if ($psacar_car->image_4->Visible) { // image 
?>
    <tr<?php echo $psacar_car->image_4->RowAttributes ?>>
        <td class="ewTableHeader">
<?php 
            echo $psacar_car->image_4->FldCaption()
?>
        </td>
        <td<?php echo $psacar_car->image_4->CellAttributes() ?>>
            <span id="el_image">
                <input 
                    type="file" 
                    name="x_image_4" 
                    id="x_image_4" 
                    title="<?php echo $psacar_car->image_4->FldTitle() ?>" 
                    size="30"<?php echo $psacar_car->image_4->EditAttributes() ?>>
            </span>
<?php 
                echo $psacar_car->image_4->CustomMsg 
?>
        </td>
    </tr>
<?php 
} 
?>
<?php 
if ($psacar_car->image_5->Visible) { // image 
?>
    <tr<?php echo $psacar_car->image_5->RowAttributes ?>>
        <td class="ewTableHeader">
<?php 
            echo $psacar_car->image_5->FldCaption() 
?>
        </td>
        <td<?php echo $psacar_car->image_5->CellAttributes() ?>>
            <span id="el_image">
                <input 
                    type="file" 
                    name="x_image_5" 
                    id="x_image_5" 
                    title="<?php echo $psacar_car->image_5->FldTitle() ?>" 
                    size="30"<?php echo $psacar_car->image_5->EditAttributes() ?>>
            </span>
<?php 
                echo $psacar_car->image_5->CustomMsg 
?>
        </td>
    </tr>
<?php 
} 
?>
</table>
</div>
</td></tr></table>
<p>
<input type="submit" name="btnAction" id="btnAction" value="<?php echo ew_BtnCaption($Language->Phrase("AddBtn")) ?>">
</form>
<script type="text/javascript">
<!--
ew_CreateEditor();  // Create DHTML editor(s)

//-->
</script>
<script language="JavaScript" type="text/javascript">
<!--

// Write your table-specific startup script here
// document.write("page loaded");
//-->

</script>
<?php include "footer.php" ?>
<?php
$psacar_car_add->Page_Terminate();
?>
<?php

//
// Page class
//
class cpsacar_car_add {
	// Page ID
	var $PageID = 'add';

	// Table name
	var $TableName = 'psacar_car';

	// Page object name
	var $PageObjName = 'psacar_car_add';

	// Page name
	function PageName() {
		return ew_CurrentPage();
	}

	// Page URL
	function PageUrl() {
		$PageUrl = ew_CurrentPage() . "?";
		global $psacar_car;
		if ($psacar_car->UseTokenInUrl) $PageUrl .= "t=" . $psacar_car->TableVar . "&"; // Add page token
		return $PageUrl;
	}

	// Page URLs
	var $AddUrl;
	var $EditUrl;
	var $CopyUrl;
	var $DeleteUrl;
	var $ViewUrl;
	var $ListUrl;

	// Export URLs
	var $ExportPrintUrl;
	var $ExportHtmlUrl;
	var $ExportExcelUrl;
	var $ExportWordUrl;
	var $ExportXmlUrl;
	var $ExportCsvUrl;

	// Update URLs
	var $InlineAddUrl;
	var $InlineCopyUrl;
	var $InlineEditUrl;
	var $GridAddUrl;
	var $GridEditUrl;
	var $MultiDeleteUrl;
	var $MultiUpdateUrl;

	// Message
	function getMessage() {
		return @$_SESSION[EW_SESSION_MESSAGE];
	}

	function setMessage($v) {
		if (@$_SESSION[EW_SESSION_MESSAGE] <> "") { // Append
			$_SESSION[EW_SESSION_MESSAGE] .= "<br>" . $v;
		} else {
			$_SESSION[EW_SESSION_MESSAGE] = $v;
		}
	}

	// Show message
	function ShowMessage() {
		$sMessage = $this->getMessage();
		$this->Message_Showing($sMessage);
		if ($sMessage <> "") { // Message in Session, display
			echo "<p><span class=\"ewMessage\">" . $sMessage . "</span></p>";
			$_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message in Session
		}
	}

	// Validate page request
	function IsPageRequest() {
		global $objForm, $psacar_car;
		if ($psacar_car->UseTokenInUrl) {
			if ($objForm)
				return ($psacar_car->TableVar == $objForm->GetValue("t"));
			if (@$_GET["t"] <> "")
				return ($psacar_car->TableVar == $_GET["t"]);
		} else {
			return TRUE;
		}
	}

	//
	// Page class constructor
	//
	function cpsacar_car_add() {
		global $conn, $Language;

		// Language object
		$Language = new cLanguage();

		// Table object (psacar_car)
		$GLOBALS["psacar_car"] = new cpsacar_car();

		// Table object (psacar_user)
		$GLOBALS['psacar_user'] = new cpsacar_user();

		// Page ID
		if (!defined("EW_PAGE_ID"))
			define("EW_PAGE_ID", 'add', TRUE);

		// Table name (for backward compatibility)
		if (!defined("EW_TABLE_NAME"))
			define("EW_TABLE_NAME", 'psacar_car', TRUE);

		// Start timer
		$GLOBALS["gsTimer"] = new cTimer();

		// Open connection
		$conn = ew_Connect();
	}

	// 
	//  Page_Init
	//
	function Page_Init() {
            global $gsExport, $gsExportFile, $UserProfile, $Language, $Security, $objForm;
            global $psacar_car;

            // Security
            $Security = new cAdvancedSecurity();
            if (!$Security->IsLoggedIn()) $Security->AutoLogin();
            if (!$Security->IsLoggedIn()) {
                    $Security->SaveLastUrl();
                    $this->Page_Terminate("login.php");
            }

            // Create form object
            $objForm = new cFormObj();

            // Global Page Loading event (in userfn*.php)
            Page_Loading();

            // Page Load event
            $this->Page_Load();
	}

	//
	// Page_Terminate
	//
	function Page_Terminate($url = "") {
		global $conn;

		// Page Unload event
		$this->Page_Unload();

		// Global Page Unloaded event (in userfn*.php)
		Page_Unloaded();

		 // Close connection
		$conn->Close();

		// Go to URL if specified
		$this->Page_Redirecting($url);
		if ($url <> "") {
			if (!EW_DEBUG_ENABLED && ob_get_length())
				ob_end_clean();
			header("Location: " . $url);
		}
		exit();
	}
	var $sDbMasterFilter = "";
	var $sDbDetailFilter = "";
	var $lPriv = 0;

	// 
	// Page main
	//
	function Page_Main() {
            global $objForm, $Language, $gsFormError, $psacar_car;

            // Load key values from QueryString
            $bCopy = TRUE;
            if (@$_GET["id"] != "") {
              $psacar_car->id->setQueryStringValue($_GET["id"]);
            } else {
              $bCopy = FALSE;
            }

            // Process form if post back
            if (@$_POST["a_add"] <> "") {
                $psacar_car->CurrentAction = $_POST["a_add"]; // Get form action
                $this->GetUploadFiles(); // Get upload files                
                $this->LoadFormValues(); // Load form values

                // Validate form
                if (!$this->ValidateForm()) {                    
                    $psacar_car->CurrentAction = "I"; // Form error, reset action
                    $this->setMessage($gsFormError);
                }
            } 
            else { // Not post back
                if ($bCopy) {
                    $psacar_car->CurrentAction = "C"; // Copy record
                } 
                else {
                    $psacar_car->CurrentAction = "I"; // Display blank record
                    $this->LoadDefaultValues(); // Load default values
                }
            }

            // Perform action based on action code
            switch ($psacar_car->CurrentAction) {
                case "I": // Blank record, no action required
                    break;
                case "C": // Copy an existing record
                    if (!$this->LoadRow()) { // Load record based on key
                        $this->setMessage($Language->Phrase("NoRecord")); // No record found
                        $this->Page_Terminate("psacar_carlist.php"); // No matching record, return to list
                    }
                    break;
                case "A": // ' Add new record
                    $psacar_car->SendEmail = TRUE; // Send email on add success

                    if ($this->AddRow()) { // Add successful
                        $this->setMessage($Language->Phrase("AddSuccess")); // Set up success message
                        $sReturnUrl = $psacar_car->getReturnUrl();
                        $this->Page_Terminate($sReturnUrl); // Clean up and return
                    } 
                    else {
                        $this->RestoreFormValues(); // Add failed, restore form values
                    }
            }

            // Render row based on row type
            $psacar_car->RowType = EW_ROWTYPE_ADD;  // Render add type

            // Render row
            $this->RenderRow();
	}

	// Get upload files
	function GetUploadFiles() {            
            global $objForm, $psacar_car;            
            // Get upload data
            if ($psacar_car->image_1->Upload->UploadFile()) {
                // No action required                
            } else {                
                echo $psacar_car->image_1->Upload->Message;
                $this->Page_Terminate();
                exit();
            }     
            
            if ($psacar_car->image_2->Upload->UploadFile()) {
                // No action required                
            } else {                
                echo $psacar_car->image_2->Upload->Message;
                $this->Page_Terminate();
                exit();
            }                                    
            
            if ($psacar_car->image_3->Upload->UploadFile()) {
                // No action required                
            } else {                
                echo $psacar_car->image_3->Upload->Message;
                $this->Page_Terminate();
                exit();
            }                                    
            
            if ($psacar_car->image_4->Upload->UploadFile()) {
                // No action required                
            } else {                
                echo $psacar_car->image_4->Upload->Message;
                $this->Page_Terminate();
                exit();
            }                                    
            
            if ($psacar_car->image_5->Upload->UploadFile()) {
                // No action required                
            } else {                
                echo $psacar_car->image_5->Upload->Message;
                $this->Page_Terminate();
                exit();
            }                                    
	}

	// Load default values
	function LoadDefaultValues() {
		global $psacar_car;
		$psacar_car->status->CurrentValue = 0;
	}

	// Load form values
	function LoadFormValues() {
            // Load from form
            global $objForm, $psacar_car;
            $psacar_car->dealer_id->setFormValue($objForm->GetValue("x_dealer_id"));
            $psacar_car->model_id->setFormValue($objForm->GetValue("x_model_id"));
            $psacar_car->year->setFormValue($objForm->GetValue("x_year"));
            $psacar_car->type_id->setFormValue($objForm->GetValue("x_type_id"));
            $psacar_car->category_id->setFormValue($objForm->GetValue("x_category_id"));
            $psacar_car->description->setFormValue($objForm->GetValue("x_description"));
            $psacar_car->price->setFormValue($objForm->GetValue("x_price"));
            $psacar_car->quality->setFormValue($objForm->GetValue("x_quality"));
            $psacar_car->post_date->setFormValue($objForm->GetValue("x_post_date"));
            $psacar_car->post_date->CurrentValue = ew_UnFormatDateTime($psacar_car->post_date->CurrentValue, 5);
            $psacar_car->expiration_date->setFormValue($objForm->GetValue("x_expiration_date"));
            $psacar_car->expiration_date->CurrentValue = ew_UnFormatDateTime($psacar_car->expiration_date->CurrentValue, 5);
            $psacar_car->internal_color_id->setFormValue($objForm->GetValue("x_internal_color_id"));
            $psacar_car->transmission->setFormValue($objForm->GetValue("x_transmission"));
            $psacar_car->legal->setFormValue($objForm->GetValue("x_legal"));
            $psacar_car->drive_train->setFormValue($objForm->GetValue("x_drive_train"));
            $psacar_car->door_count->setFormValue($objForm->GetValue("x_door_count"));
            $psacar_car->fuel->setFormValue($objForm->GetValue("x_fuel"));
            $psacar_car->vat->setFormValue($objForm->GetValue("x_vat"));
            $psacar_car->destinations->setFormValue($objForm->GetValue("x_destinations"));
            $psacar_car->rent_type->setFormValue($objForm->GetValue("x_rent_type"));
            $psacar_car->vehicle_type_id->setFormValue($objForm->GetValue("x_vehicle_type_id"));
            $psacar_car->is_driver->setFormValue($objForm->GetValue("x_is_driver"));
            $psacar_car->vehicle_id_number->setFormValue($objForm->GetValue("x_vehicle_id_number"));
            $psacar_car->negotiate->setFormValue($objForm->GetValue("x_negotiate"));
            $psacar_car->duration->setFormValue($objForm->GetValue("x_duration"));
            $psacar_car->create_date->setFormValue($objForm->GetValue("x_create_date"));
            $psacar_car->create_date->CurrentValue = ew_UnFormatDateTime($psacar_car->create_date->CurrentValue, 5);
            $psacar_car->end_date->setFormValue($objForm->GetValue("x_end_date"));
            $psacar_car->end_date->CurrentValue = ew_UnFormatDateTime($psacar_car->end_date->CurrentValue, 5);
            $psacar_car->status->setFormValue($objForm->GetValue("x_status"));
            $psacar_car->code->setFormValue($objForm->GetValue("x_code"));
            $psacar_car->created_date->setFormValue($objForm->GetValue("x_created_date"));
            $psacar_car->created_date->CurrentValue = ew_UnFormatDateTime($psacar_car->created_date->CurrentValue, 5);
            $psacar_car->modified_date->setFormValue($objForm->GetValue("x_modified_date"));
            $psacar_car->modified_date->CurrentValue = ew_UnFormatDateTime($psacar_car->modified_date->CurrentValue, 5);
            $psacar_car->id->setFormValue($objForm->GetValue("x_id"));
	}

	// Restore form values
	function RestoreFormValues() {
            global $objForm, $psacar_car;
            $psacar_car->id->CurrentValue = $psacar_car->id->FormValue;
            $psacar_car->dealer_id->CurrentValue = $psacar_car->dealer_id->FormValue;
            $psacar_car->model_id->CurrentValue = $psacar_car->model_id->FormValue;
            $psacar_car->year->CurrentValue = $psacar_car->year->FormValue;
            $psacar_car->type_id->CurrentValue = $psacar_car->type_id->FormValue;
            $psacar_car->category_id->CurrentValue = $psacar_car->category_id->FormValue;
            $psacar_car->description->CurrentValue = $psacar_car->description->FormValue;
            $psacar_car->price->CurrentValue = $psacar_car->price->FormValue;
            $psacar_car->quality->CurrentValue = $psacar_car->quality->FormValue;
            $psacar_car->post_date->CurrentValue = $psacar_car->post_date->FormValue;
            $psacar_car->post_date->CurrentValue = ew_UnFormatDateTime($psacar_car->post_date->CurrentValue, 5);
            $psacar_car->expiration_date->CurrentValue = $psacar_car->expiration_date->FormValue;
            $psacar_car->expiration_date->CurrentValue = ew_UnFormatDateTime($psacar_car->expiration_date->CurrentValue, 5);
            $psacar_car->internal_color_id->CurrentValue = $psacar_car->internal_color_id->FormValue;
            $psacar_car->transmission->CurrentValue = $psacar_car->transmission->FormValue;
            $psacar_car->legal->CurrentValue = $psacar_car->legal->FormValue;
            $psacar_car->drive_train->CurrentValue = $psacar_car->drive_train->FormValue;
            $psacar_car->door_count->CurrentValue = $psacar_car->door_count->FormValue;
            $psacar_car->fuel->CurrentValue = $psacar_car->fuel->FormValue;
            $psacar_car->vat->CurrentValue = $psacar_car->vat->FormValue;
            $psacar_car->destinations->CurrentValue = $psacar_car->destinations->FormValue;
            $psacar_car->rent_type->CurrentValue = $psacar_car->rent_type->FormValue;
            $psacar_car->vehicle_type_id->CurrentValue = $psacar_car->vehicle_type_id->FormValue;
            $psacar_car->is_driver->CurrentValue = $psacar_car->is_driver->FormValue;
            $psacar_car->vehicle_id_number->CurrentValue = $psacar_car->vehicle_id_number->FormValue;
            $psacar_car->negotiate->CurrentValue = $psacar_car->negotiate->FormValue;
            $psacar_car->duration->CurrentValue = $psacar_car->duration->FormValue;
            $psacar_car->create_date->CurrentValue = $psacar_car->create_date->FormValue;
            $psacar_car->create_date->CurrentValue = ew_UnFormatDateTime($psacar_car->create_date->CurrentValue, 5);
            $psacar_car->end_date->CurrentValue = $psacar_car->end_date->FormValue;
            $psacar_car->end_date->CurrentValue = ew_UnFormatDateTime($psacar_car->end_date->CurrentValue, 5);
            $psacar_car->status->CurrentValue = $psacar_car->status->FormValue;
            $psacar_car->code->CurrentValue = $psacar_car->code->FormValue;
            $psacar_car->created_date->CurrentValue = $psacar_car->created_date->FormValue;
            $psacar_car->created_date->CurrentValue = ew_UnFormatDateTime($psacar_car->created_date->CurrentValue, 5);
            $psacar_car->modified_date->CurrentValue = $psacar_car->modified_date->FormValue;
            $psacar_car->modified_date->CurrentValue = ew_UnFormatDateTime($psacar_car->modified_date->CurrentValue, 5);
	}

	// Load row based on key values
	function LoadRow() {
            global $conn, $Security, $psacar_car;
            $sFilter = $psacar_car->KeyFilter();

            // Call Row Selecting event
            $psacar_car->Row_Selecting($sFilter);

            // Load SQL based on filter
            $psacar_car->CurrentFilter = $sFilter;
            $sSql = $psacar_car->SQL();
            $res = FALSE;
            $rs = ew_LoadRecordset($sSql);
            if ($rs && !$rs->EOF) {
                    $res = TRUE;
                    $this->LoadRowValues($rs); // Load row values

                    // Call Row Selected event
                    $psacar_car->Row_Selected($rs);
                    $rs->Close();
            }
            return $res;
	}

	// Load row values from recordset
	function LoadRowValues(&$rs) {
		global $conn, $psacar_car;
		$psacar_car->id->setDbValue($rs->fields('id'));
		$psacar_car->dealer_id->setDbValue($rs->fields('dealer_id'));
		$psacar_car->model_id->setDbValue($rs->fields('model_id'));
		$psacar_car->year->setDbValue($rs->fields('year'));
		$psacar_car->external_color_id->setDbValue($rs->fields('external_color_id'));
		$psacar_car->type_id->setDbValue($rs->fields('type_id'));
		$psacar_car->category_id->setDbValue($rs->fields('category_id'));
		$psacar_car->description->setDbValue($rs->fields('description'));
		$psacar_car->price->setDbValue($rs->fields('price'));
		$psacar_car->quality->setDbValue($rs->fields('quality'));
		$psacar_car->post_by->setDbValue($rs->fields('post_by'));
		$psacar_car->post_date->setDbValue($rs->fields('post_date'));
		$psacar_car->expiration_date->setDbValue($rs->fields('expiration_date'));
		$psacar_car->number_votes->setDbValue($rs->fields('number_votes'));
		$psacar_car->total_points->setDbValue($rs->fields('total_points'));
		$psacar_car->dec_avg->setDbValue($rs->fields('dec_avg'));
		$psacar_car->whole_avg->setDbValue($rs->fields('whole_avg'));
		$psacar_car->internal_color_id->setDbValue($rs->fields('internal_color_id'));
		$psacar_car->transmission->setDbValue($rs->fields('transmission'));
		$psacar_car->legal->setDbValue($rs->fields('legal'));
		$psacar_car->import_tax->setDbValue($rs->fields('import_tax'));
		$psacar_car->drive_train->setDbValue($rs->fields('drive_train'));
		$psacar_car->door_count->setDbValue($rs->fields('door_count'));
		$psacar_car->fuel->setDbValue($rs->fields('fuel'));
		$psacar_car->vat->setDbValue($rs->fields('vat'));
		$psacar_car->destinations->setDbValue($rs->fields('destinations'));
		$psacar_car->rent_type->setDbValue($rs->fields('rent_type'));
		$psacar_car->vehicle_type_id->setDbValue($rs->fields('vehicle_type_id'));
		$psacar_car->is_driver->setDbValue($rs->fields('is_driver'));
		$psacar_car->image->Upload->DbValue = $rs->fields('image');
		$psacar_car->vehicle_id_number->setDbValue($rs->fields('vehicle_id_number'));
		$psacar_car->negotiate->setDbValue($rs->fields('negotiate'));
		$psacar_car->duration_type->setDbValue($rs->fields('duration_type'));
		$psacar_car->duration->setDbValue($rs->fields('duration'));
		$psacar_car->create_date->setDbValue($rs->fields('create_date'));
		$psacar_car->end_date->setDbValue($rs->fields('end_date'));
		$psacar_car->status->setDbValue($rs->fields('status'));
		$psacar_car->code->setDbValue($rs->fields('code'));
		$psacar_car->created_date->setDbValue($rs->fields('created_date'));
		$psacar_car->modified_date->setDbValue($rs->fields('modified_date'));
	}

	// Render row values based on field settings
	function RenderRow() {
		global $conn, $Security, $Language, $psacar_car;

		// Initialize URLs
		// Call Row_Rendering event

		$psacar_car->Row_Rendering();

		// Common render codes for all row types
		// dealer_id

		$psacar_car->dealer_id->CellCssStyle = ""; $psacar_car->dealer_id->CellCssClass = "";
		$psacar_car->dealer_id->CellAttrs = array(); $psacar_car->dealer_id->ViewAttrs = array(); $psacar_car->dealer_id->EditAttrs = array();

		// model_id
		$psacar_car->model_id->CellCssStyle = ""; $psacar_car->model_id->CellCssClass = "";
		$psacar_car->model_id->CellAttrs = array(); $psacar_car->model_id->ViewAttrs = array(); $psacar_car->model_id->EditAttrs = array();

		// year
		$psacar_car->year->CellCssStyle = ""; $psacar_car->year->CellCssClass = "";
		$psacar_car->year->CellAttrs = array(); $psacar_car->year->ViewAttrs = array(); $psacar_car->year->EditAttrs = array();

                // type_id
		$psacar_car->type_id->CellCssStyle = ""; $psacar_car->type_id->CellCssClass = "";
		$psacar_car->type_id->CellAttrs = array(); $psacar_car->type_id->ViewAttrs = array(); $psacar_car->type_id->EditAttrs = array();

		// category_id
		$psacar_car->category_id->CellCssStyle = ""; $psacar_car->category_id->CellCssClass = "";
		$psacar_car->category_id->CellAttrs = array(); $psacar_car->category_id->ViewAttrs = array(); $psacar_car->category_id->EditAttrs = array();

		// description
		$psacar_car->description->CellCssStyle = ""; $psacar_car->description->CellCssClass = "";
		$psacar_car->description->CellAttrs = array(); $psacar_car->description->ViewAttrs = array(); $psacar_car->description->EditAttrs = array();

		// price
		$psacar_car->price->CellCssStyle = ""; $psacar_car->price->CellCssClass = "";
		$psacar_car->price->CellAttrs = array(); $psacar_car->price->ViewAttrs = array(); $psacar_car->price->EditAttrs = array();

		// quality
		$psacar_car->quality->CellCssStyle = ""; $psacar_car->quality->CellCssClass = "";
		$psacar_car->quality->CellAttrs = array(); $psacar_car->quality->ViewAttrs = array(); $psacar_car->quality->EditAttrs = array();

		// post_date
		$psacar_car->post_date->CellCssStyle = ""; $psacar_car->post_date->CellCssClass = "";
		$psacar_car->post_date->CellAttrs = array(); $psacar_car->post_date->ViewAttrs = array(); $psacar_car->post_date->EditAttrs = array();

		// expiration_date
		$psacar_car->expiration_date->CellCssStyle = ""; $psacar_car->expiration_date->CellCssClass = "";
		$psacar_car->expiration_date->CellAttrs = array(); $psacar_car->expiration_date->ViewAttrs = array(); $psacar_car->expiration_date->EditAttrs = array();

		// internal_color_id
		$psacar_car->internal_color_id->CellCssStyle = ""; $psacar_car->internal_color_id->CellCssClass = "";
		$psacar_car->internal_color_id->CellAttrs = array(); $psacar_car->internal_color_id->ViewAttrs = array(); $psacar_car->internal_color_id->EditAttrs = array();

		// transmission
		$psacar_car->transmission->CellCssStyle = ""; $psacar_car->transmission->CellCssClass = "";
		$psacar_car->transmission->CellAttrs = array(); $psacar_car->transmission->ViewAttrs = array(); $psacar_car->transmission->EditAttrs = array();

		// legal
		$psacar_car->legal->CellCssStyle = ""; $psacar_car->legal->CellCssClass = "";
		$psacar_car->legal->CellAttrs = array(); $psacar_car->legal->ViewAttrs = array(); $psacar_car->legal->EditAttrs = array();

		// drive_train
		$psacar_car->drive_train->CellCssStyle = ""; $psacar_car->drive_train->CellCssClass = "";
		$psacar_car->drive_train->CellAttrs = array(); $psacar_car->drive_train->ViewAttrs = array(); $psacar_car->drive_train->EditAttrs = array();

		// door_count
		$psacar_car->door_count->CellCssStyle = ""; $psacar_car->door_count->CellCssClass = "";
		$psacar_car->door_count->CellAttrs = array(); $psacar_car->door_count->ViewAttrs = array(); $psacar_car->door_count->EditAttrs = array();

		// fuel
		$psacar_car->fuel->CellCssStyle = ""; $psacar_car->fuel->CellCssClass = "";
		$psacar_car->fuel->CellAttrs = array(); $psacar_car->fuel->ViewAttrs = array(); $psacar_car->fuel->EditAttrs = array();

		// vat
		$psacar_car->vat->CellCssStyle = ""; $psacar_car->vat->CellCssClass = "";
		$psacar_car->vat->CellAttrs = array(); $psacar_car->vat->ViewAttrs = array(); $psacar_car->vat->EditAttrs = array();

		// destinations
		$psacar_car->destinations->CellCssStyle = ""; $psacar_car->destinations->CellCssClass = "";
		$psacar_car->destinations->CellAttrs = array(); $psacar_car->destinations->ViewAttrs = array(); $psacar_car->destinations->EditAttrs = array();

		// rent_type
		$psacar_car->rent_type->CellCssStyle = ""; $psacar_car->rent_type->CellCssClass = "";
		$psacar_car->rent_type->CellAttrs = array(); $psacar_car->rent_type->ViewAttrs = array(); $psacar_car->rent_type->EditAttrs = array();

		// vehicle_type_id
		$psacar_car->vehicle_type_id->CellCssStyle = ""; $psacar_car->vehicle_type_id->CellCssClass = "";
		$psacar_car->vehicle_type_id->CellAttrs = array(); $psacar_car->vehicle_type_id->ViewAttrs = array(); $psacar_car->vehicle_type_id->EditAttrs = array();

		// is_driver
		$psacar_car->is_driver->CellCssStyle = ""; $psacar_car->is_driver->CellCssClass = "";
		$psacar_car->is_driver->CellAttrs = array(); $psacar_car->is_driver->ViewAttrs = array(); $psacar_car->is_driver->EditAttrs = array();

		// image
		$psacar_car->image->CellCssStyle = ""; $psacar_car->image->CellCssClass = "";
		$psacar_car->image->CellAttrs = array(); $psacar_car->image->ViewAttrs = array(); $psacar_car->image->EditAttrs = array();

		// vehicle_id_number
		$psacar_car->vehicle_id_number->CellCssStyle = ""; $psacar_car->vehicle_id_number->CellCssClass = "";
		$psacar_car->vehicle_id_number->CellAttrs = array(); $psacar_car->vehicle_id_number->ViewAttrs = array(); $psacar_car->vehicle_id_number->EditAttrs = array();

		// negotiate
		$psacar_car->negotiate->CellCssStyle = ""; $psacar_car->negotiate->CellCssClass = "";
		$psacar_car->negotiate->CellAttrs = array(); $psacar_car->negotiate->ViewAttrs = array(); $psacar_car->negotiate->EditAttrs = array();

		// duration
		$psacar_car->duration->CellCssStyle = ""; $psacar_car->duration->CellCssClass = "";
		$psacar_car->duration->CellAttrs = array(); $psacar_car->duration->ViewAttrs = array(); $psacar_car->duration->EditAttrs = array();

		// create_date
		$psacar_car->create_date->CellCssStyle = ""; $psacar_car->create_date->CellCssClass = "";
		$psacar_car->create_date->CellAttrs = array(); $psacar_car->create_date->ViewAttrs = array(); $psacar_car->create_date->EditAttrs = array();

		// end_date
		$psacar_car->end_date->CellCssStyle = ""; $psacar_car->end_date->CellCssClass = "";
		$psacar_car->end_date->CellAttrs = array(); $psacar_car->end_date->ViewAttrs = array(); $psacar_car->end_date->EditAttrs = array();

		// status
		$psacar_car->status->CellCssStyle = ""; $psacar_car->status->CellCssClass = "";
		$psacar_car->status->CellAttrs = array(); $psacar_car->status->ViewAttrs = array(); $psacar_car->status->EditAttrs = array();

		// code
		$psacar_car->code->CellCssStyle = ""; $psacar_car->code->CellCssClass = "";
		$psacar_car->code->CellAttrs = array(); $psacar_car->code->ViewAttrs = array(); $psacar_car->code->EditAttrs = array();

		// created_date
		$psacar_car->created_date->CellCssStyle = ""; $psacar_car->created_date->CellCssClass = "";
		$psacar_car->created_date->CellAttrs = array(); $psacar_car->created_date->ViewAttrs = array(); $psacar_car->created_date->EditAttrs = array();

		// modified_date
		$psacar_car->modified_date->CellCssStyle = ""; $psacar_car->modified_date->CellCssClass = "";
		$psacar_car->modified_date->CellAttrs = array(); $psacar_car->modified_date->ViewAttrs = array(); $psacar_car->modified_date->EditAttrs = array();
		if ($psacar_car->RowType == EW_ROWTYPE_VIEW) { 
                    // View row
		} elseif ($psacar_car->RowType == EW_ROWTYPE_ADD) { 
                    // Add row

			// dealer_id
			$psacar_car->dealer_id->EditCustomAttributes = "";
                            $sFilterWrk = "";
			$sSqlWrk = "SELECT `id`, `name`, '' AS Disp2Fld, '' AS SelectFilterFld FROM `psacar_member`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = $conn->Execute($sSqlWrk);
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
			$psacar_car->dealer_id->EditValue = $arwrk;

			// model_id
			$psacar_car->model_id->EditCustomAttributes = "";
                        $sFilterWrk = "";
			$sSqlWrk = "SELECT `id`, `name`, '' AS Disp2Fld, '' AS SelectFilterFld FROM psacar_model";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
                            if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = $conn->Execute($sSqlWrk);
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
			$psacar_car->model_id->EditValue = $arwrk;

			// type_id
			$psacar_car->type_id->EditCustomAttributes = "";
				$sFilterWrk = "";
			$sSqlWrk = "SELECT `id`, `name`, '' AS Disp2Fld, '' AS SelectFilterFld FROM `psacar_car_type`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = $conn->Execute($sSqlWrk);
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
			$psacar_car->type_id->EditValue = $arwrk;

			// category_id
			$psacar_car->category_id->EditCustomAttributes = "";
				$sFilterWrk = "";
			$sSqlWrk = "SELECT `category_id`, `category_name`, '' AS Disp2Fld, '' AS SelectFilterFld FROM `psacar_category`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = $conn->Execute($sSqlWrk);
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
			$psacar_car->category_id->EditValue = $arwrk;

			// description
			$psacar_car->description->EditCustomAttributes = "";
			$psacar_car->description->EditValue = ew_HtmlEncode($psacar_car->description->CurrentValue);

			// year
			$psacar_car->year->EditCustomAttributes = "";
			$psacar_car->year->EditValue = ew_HtmlEncode($psacar_car->year->CurrentValue);

                        // price
			$psacar_car->price->EditCustomAttributes = "";
			$psacar_car->price->EditValue = ew_HtmlEncode($psacar_car->price->CurrentValue);

			// quality
			$psacar_car->quality->EditCustomAttributes = "";
			$psacar_car->quality->EditValue = ew_HtmlEncode($psacar_car->quality->CurrentValue);
			if (strval($psacar_car->quality->CurrentValue) <> "") {
				$sFilterWrk = "`code` = " . ew_AdjustSql($psacar_car->quality->CurrentValue) . "";
			$sSqlWrk = "SELECT `mileage` FROM `psacar_mileage`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$psacar_car->quality->EditValue = $rswrk->fields('mileage');
					$rswrk->Close();
				} else {
					$psacar_car->quality->EditValue = $psacar_car->quality->CurrentValue;
				}
			} else {
				$psacar_car->quality->EditValue = NULL;
			}

			// post_date
			$psacar_car->post_date->EditCustomAttributes = "";
			$psacar_car->post_date->EditValue = ew_HtmlEncode(ew_FormatDateTime($psacar_car->post_date->CurrentValue, 5));

			// expiration_date
			$psacar_car->expiration_date->EditCustomAttributes = "";
			$psacar_car->expiration_date->EditValue = ew_HtmlEncode(ew_FormatDateTime($psacar_car->expiration_date->CurrentValue, 5));

			// external_color_id
			$psacar_car->external_color_id->EditCustomAttributes = "";
                        $sFilterWrk = "category_id = 2";
			$sSqlWrk = "SELECT `id`, `color`, '' AS Disp2Fld, '' AS SelectFilterFld FROM `psacar_color`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = $conn->Execute($sSqlWrk . ' ORDER BY `color`');
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
			$psacar_car->external_color_id->EditValue = $arwrk;
                        
			// internal_color_id
			$psacar_car->internal_color_id->EditCustomAttributes = "";
                        $sFilterWrk = "category_id = 1";
			$sSqlWrk = "SELECT `id`, `color`, '' AS Disp2Fld, '' AS SelectFilterFld FROM `psacar_color`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = $conn->Execute($sSqlWrk . ' ORDER BY `color`');
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
			$psacar_car->internal_color_id->EditValue = $arwrk;

			// transmission
			$psacar_car->transmission->EditCustomAttributes = "";
                        $sFilterWrk = "";
			$sSqlWrk = "SELECT `id`, `transmission`, '' AS Disp2Fld, '' AS SelectFilterFld FROM `psacar_transmission`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = $conn->Execute($sSqlWrk);
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
			$psacar_car->transmission->EditValue = $arwrk;

			// legal
			$psacar_car->legal->EditCustomAttributes = "";
			$arwrk = array();
			$arwrk[] = array("0", "Owner transfer fee included");
			$arwrk[] = array("1", "Owner transfer fee not included");
			$arwrk[] = array("2", "Others");
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
			$psacar_car->legal->EditValue = $arwrk;

			// drive_train
			$psacar_car->drive_train->EditCustomAttributes = "";
                        $sFilterWrk = "";
			$sSqlWrk = "SELECT `id`, `drivetrain`, '' AS Disp2Fld, '' AS SelectFilterFld FROM `psacar_drivetrain`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = $conn->Execute($sSqlWrk);
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
			$psacar_car->drive_train->EditValue = $arwrk;

			// door_count
			$psacar_car->door_count->EditCustomAttributes = "";
                        $arwrk = array();
                        $arwrk[] = array("0", $Language->Phrase("PleaseSelect"));
                        for($counter = 1; $counter <= 10; $counter++)			
                            $arwrk[] = array($counter, $counter);
			$psacar_car->door_count->EditValue = $arwrk;

			// fuel
			$psacar_car->fuel->EditCustomAttributes = "";
				$sFilterWrk = "";
			$sSqlWrk = "SELECT `id`, `fuel`, '' AS Disp2Fld, '' AS SelectFilterFld FROM `psacar_fuel`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
                            if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = $conn->Execute($sSqlWrk);
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			$psacar_car->fuel->EditValue = $arwrk;

			// vat
			$psacar_car->vat->EditCustomAttributes = "";
			$arwrk = array();
			$arwrk[] = array("0", "Included");
			$arwrk[] = array("1", "Not included");
			$psacar_car->vat->EditValue = $arwrk;

			// destinations
			$psacar_car->destinations->EditCustomAttributes = "";
			$arwrk = array();
			$arwrk[] = array("0", "Airport Pickup");
			$arwrk[] = array("1", "Airport Drop off");
			$arwrk[] = array("2", "Hourly");
			$arwrk[] = array("3", "Hafday");
			$arwrk[] = array("4", "Full day");
			$arwrk[] = array("5", "Tour Package");
			$arwrk[] = array("", "");
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
			$psacar_car->destinations->EditValue = $arwrk;

			// rent_type
			$psacar_car->rent_type->EditCustomAttributes = "";
			$arwrk = array();
			$arwrk[] = array("0", "Long term leasing");
			$arwrk[] = array("1", "Short term leasing");
			$arwrk[] = array("2", "Tour Package");
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
			$psacar_car->rent_type->EditValue = $arwrk;

			// vehicle_type_id
			$psacar_car->vehicle_type_id->EditCustomAttributes = "";
			$arwrk = array();
			$arwrk[] = array("0", "Buy");
			$arwrk[] = array("1", "Sale");
			$arwrk[] = array("2", "Rent");
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
			$psacar_car->vehicle_type_id->EditValue = $arwrk;

			// is_driver
			$psacar_car->is_driver->EditCustomAttributes = "";
			$arwrk = array();
			$arwrk[] = array("0", "With Driver");
			$arwrk[] = array("1", "Without Driver");
			$psacar_car->is_driver->EditValue = $arwrk;

			// image
			$psacar_car->image->EditCustomAttributes = "";
			if (!ew_Empty($psacar_car->image->Upload->DbValue)) {
				$psacar_car->image->EditValue = $psacar_car->image->Upload->DbValue;
			} else {
				$psacar_car->image->EditValue = "";
			}

			// vehicle_id_number
			$psacar_car->vehicle_id_number->EditCustomAttributes = "";
			$psacar_car->vehicle_id_number->EditValue = ew_HtmlEncode($psacar_car->vehicle_id_number->CurrentValue);

			// negotiate
			$psacar_car->negotiate->EditCustomAttributes = "";
			$arwrk = array();
			$arwrk[] = array("1", "Yes/No");
			$psacar_car->negotiate->EditValue = $arwrk;

			// duration
			$psacar_car->duration->EditCustomAttributes = "";
			$psacar_car->duration->EditValue = ew_HtmlEncode($psacar_car->duration->CurrentValue);

			// create_date
			$psacar_car->create_date->EditCustomAttributes = "";
			$psacar_car->create_date->EditValue = ew_HtmlEncode(ew_FormatDateTime($psacar_car->create_date->CurrentValue, 5));

			// end_date
			$psacar_car->end_date->EditCustomAttributes = "";
			$psacar_car->end_date->EditValue = ew_HtmlEncode(ew_FormatDateTime($psacar_car->end_date->CurrentValue, 5));

			// status
			$psacar_car->status->EditCustomAttributes = "";
			$arwrk = array();
			$arwrk[] = array("0", "Pending");
			$arwrk[] = array("1", "Approved");
			$arwrk[] = array("2", "Deleted");
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
			$psacar_car->status->EditValue = $arwrk;

			// code
			$psacar_car->code->EditCustomAttributes = "";
			$psacar_car->code->EditValue = ew_HtmlEncode($psacar_car->code->CurrentValue);

			// created_date
			$psacar_car->created_date->EditCustomAttributes = "";
			$psacar_car->created_date->EditValue = ew_HtmlEncode(ew_FormatDateTime($psacar_car->created_date->CurrentValue, 5));

			// modified_date
			$psacar_car->modified_date->EditCustomAttributes = "";
			$psacar_car->modified_date->EditValue = ew_HtmlEncode(ew_FormatDateTime($psacar_car->modified_date->CurrentValue, 5));
		}

		// Call Row Rendered event
		if ($psacar_car->RowType <> EW_ROWTYPE_AGGREGATEINIT)
			$psacar_car->Row_Rendered();
	}

	// Validate form
	function ValidateForm() {
            global $Language, $gsFormError, $psacar_car;
            
            // Initialize form error message
            $gsFormError = "";
            if (!ew_CheckFileType($psacar_car->image_1->Upload->FileName)) {
                    $gsFormError .= ($gsFormError <> "") ? "<br>" : "";
                    $gsFormError .= $Language->Phrase("WrongFileType");
            }
            if ($psacar_car->image_1->Upload->FileSize > 0 && EW_MAX_FILE_SIZE > 0 && $psacar_car->image_1->Upload->FileSize > EW_MAX_FILE_SIZE) {
                    $gsFormError .= ($gsFormError <> "") ? "<br>" : "";
                    $gsFormError .= str_replace("%s", EW_MAX_FILE_SIZE, $Language->Phrase("MaxFileSize"));
            }

            if (!ew_CheckFileType($psacar_car->image_2->Upload->FileName)) {
                $gsFormError .= ($gsFormError <> "") ? "<br>" : "";
                $gsFormError .= $Language->Phrase("WrongFileType");
            }
            if ($psacar_car->image_2->Upload->FileSize > 0 && EW_MAX_FILE_SIZE > 0 && $psacar_car->image_2->Upload->FileSize > EW_MAX_FILE_SIZE) {
                $gsFormError .= ($gsFormError <> "") ? "<br>" : "";
                $gsFormError .= str_replace("%s", EW_MAX_FILE_SIZE, $Language->Phrase("MaxFileSize"));
            }

            if (!ew_CheckFileType($psacar_car->image_3->Upload->FileName)) {
                $gsFormError .= ($gsFormError <> "") ? "<br>" : "";
                $gsFormError .= $Language->Phrase("WrongFileType");
            }
            if ($psacar_car->image_3->Upload->FileSize > 0 && EW_MAX_FILE_SIZE > 0 && $psacar_car->image_3->Upload->FileSize > EW_MAX_FILE_SIZE) {
                $gsFormError .= ($gsFormError <> "") ? "<br>" : "";
                $gsFormError .= str_replace("%s", EW_MAX_FILE_SIZE, $Language->Phrase("MaxFileSize"));
            }
            
            if (!ew_CheckFileType($psacar_car->image_4->Upload->FileName)) {
                $gsFormError .= ($gsFormError <> "") ? "<br>" : "";
                $gsFormError .= $Language->Phrase("WrongFileType");
            }
            if ($psacar_car->image_4->Upload->FileSize > 0 && EW_MAX_FILE_SIZE > 0 && $psacar_car->image_4->Upload->FileSize > EW_MAX_FILE_SIZE) {
                $gsFormError .= ($gsFormError <> "") ? "<br>" : "";
                $gsFormError .= str_replace("%s", EW_MAX_FILE_SIZE, $Language->Phrase("MaxFileSize"));
            }
            
            if (!ew_CheckFileType($psacar_car->image_5->Upload->FileName)) {
                $gsFormError .= ($gsFormError <> "") ? "<br>" : "";
                $gsFormError .= $Language->Phrase("WrongFileType");
            }
            if ($psacar_car->image_5->Upload->FileSize > 0 && EW_MAX_FILE_SIZE > 0 && $psacar_car->image_5->Upload->FileSize > EW_MAX_FILE_SIZE) {
                $gsFormError .= ($gsFormError <> "") ? "<br>" : "";
                $gsFormError .= str_replace("%s", EW_MAX_FILE_SIZE, $Language->Phrase("MaxFileSize"));
            }
            
            // Check if validation required
            if (!EW_SERVER_VALIDATE)
                    return ($gsFormError == "");
            if (!is_null($psacar_car->dealer_id->FormValue) && $psacar_car->dealer_id->FormValue == "") {
                    $gsFormError .= ($gsFormError <> "") ? "<br>" : "";
                    $gsFormError .= $Language->Phrase("EnterRequiredField") . " - " . $psacar_car->dealer_id->FldCaption();
            }
            if (!is_null($psacar_car->model_id->FormValue) && $psacar_car->model_id->FormValue == "") {
                    $gsFormError .= ($gsFormError <> "") ? "<br>" : "";
                    $gsFormError .= $Language->Phrase("EnterRequiredField") . " - " . $psacar_car->model_id->FldCaption();
            }
            if (!is_null($psacar_car->category_id->FormValue) && $psacar_car->category_id->FormValue == "") {
                    $gsFormError .= ($gsFormError <> "") ? "<br>" : "";
                    $gsFormError .= $Language->Phrase("EnterRequiredField") . " - " . $psacar_car->category_id->FldCaption();
            }
            if (!ew_CheckNumber($psacar_car->price->FormValue)) {
                    if ($gsFormError <> "") $gsFormError .= "<br>";
                    $gsFormError .= $psacar_car->price->FldErrMsg();
            }
            if (!ew_CheckInteger($psacar_car->quality->FormValue)) {
                    if ($gsFormError <> "") $gsFormError .= "<br>";
                    $gsFormError .= $psacar_car->quality->FldErrMsg();
            }
            if (!ew_CheckDate($psacar_car->post_date->FormValue)) {
                    if ($gsFormError <> "") $gsFormError .= "<br>";
                    $gsFormError .= $psacar_car->post_date->FldErrMsg();
            }
            if (!is_null($psacar_car->expiration_date->FormValue) && $psacar_car->expiration_date->FormValue == "") {
                    $gsFormError .= ($gsFormError <> "") ? "<br>" : "";
                    $gsFormError .= $Language->Phrase("EnterRequiredField") . " - " . $psacar_car->expiration_date->FldCaption();
            }
            if (!ew_CheckDate($psacar_car->expiration_date->FormValue)) {
                    if ($gsFormError <> "") $gsFormError .= "<br>";
                    $gsFormError .= $psacar_car->expiration_date->FldErrMsg();
            }
            if (!is_null($psacar_car->vehicle_id_number->FormValue) && $psacar_car->vehicle_id_number->FormValue == "") {
                    $gsFormError .= ($gsFormError <> "") ? "<br>" : "";
                    $gsFormError .= $Language->Phrase("EnterRequiredField") . " - " . $psacar_car->vehicle_id_number->FldCaption();
            }
            if (!ew_CheckInteger($psacar_car->duration->FormValue)) {
                    if ($gsFormError <> "") $gsFormError .= "<br>";
                    $gsFormError .= $psacar_car->duration->FldErrMsg();
            }
            if (!ew_CheckDate($psacar_car->create_date->FormValue)) {
                    if ($gsFormError <> "") $gsFormError .= "<br>";
                    $gsFormError .= $psacar_car->create_date->FldErrMsg();
            }
            if (!ew_CheckDate($psacar_car->end_date->FormValue)) {
                    if ($gsFormError <> "") $gsFormError .= "<br>";
                    $gsFormError .= $psacar_car->end_date->FldErrMsg();
            }
            if (!ew_CheckDate($psacar_car->created_date->FormValue)) {
                    if ($gsFormError <> "") $gsFormError .= "<br>";
                    $gsFormError .= $psacar_car->created_date->FldErrMsg();
            }
            if (!ew_CheckDate($psacar_car->modified_date->FormValue)) {
                    if ($gsFormError <> "") $gsFormError .= "<br>";
                    $gsFormError .= $psacar_car->modified_date->FldErrMsg();
            }

            // Return validate result
            $ValidateForm = ($gsFormError == "");

            // Call Form_CustomValidate event
            $sFormCustomError = "";
            $ValidateForm = $ValidateForm && $this->Form_CustomValidate($sFormCustomError);
            if ($sFormCustomError <> "") {
                    $gsFormError .= ($gsFormError <> "") ? "<br>" : "";
                    $gsFormError .= $sFormCustomError;
            }
            return $ValidateForm;
	}

	// Add record
	function AddRow() {
            global $conn, $Language, $Security, $psacar_car;
            $rsnew = array();
            
            // dealer_id
            $psacar_car->dealer_id->SetDbValueDef($rsnew, $psacar_car->dealer_id->CurrentValue, 0, FALSE);

            // model_id
            $psacar_car->model_id->SetDbValueDef($rsnew, $psacar_car->model_id->CurrentValue, 0, FALSE);

            // year
            $psacar_car->year->SetDbValueDef($rsnew, $psacar_car->year->CurrentValue, 0, FALSE);

            // type_id
            $psacar_car->type_id->SetDbValueDef($rsnew, $psacar_car->type_id->CurrentValue, NULL, FALSE);

            // category_id
            $psacar_car->category_id->SetDbValueDef($rsnew, $psacar_car->category_id->CurrentValue, 0, FALSE);

            // description
            $psacar_car->description->SetDbValueDef($rsnew, $psacar_car->description->CurrentValue, NULL, FALSE);

            // price
            $psacar_car->price->SetDbValueDef($rsnew, $psacar_car->price->CurrentValue, NULL, FALSE);

            // quality
            $psacar_car->quality->SetDbValueDef($rsnew, $psacar_car->quality->CurrentValue, NULL, FALSE);

            // post_date
            $psacar_car->post_date->SetDbValueDef($rsnew, ew_UnFormatDateTime($psacar_car->post_date->CurrentValue, 5, FALSE), ew_CurrentDate());

            // expiration_date
            $psacar_car->expiration_date->SetDbValueDef($rsnew, ew_UnFormatDateTime($psacar_car->expiration_date->CurrentValue, 5, FALSE), ew_CurrentDate());

            // internal_color_id
            $psacar_car->internal_color_id->SetDbValueDef($rsnew, $psacar_car->internal_color_id->CurrentValue, NULL, FALSE);

            // transmission
            $psacar_car->transmission->SetDbValueDef($rsnew, $psacar_car->transmission->CurrentValue, NULL, FALSE);

            // legal
            $psacar_car->legal->SetDbValueDef($rsnew, $psacar_car->legal->CurrentValue, NULL, FALSE);

            // drive_train
            $psacar_car->drive_train->SetDbValueDef($rsnew, $psacar_car->drive_train->CurrentValue, NULL, FALSE);

            // door_count
            $psacar_car->door_count->SetDbValueDef($rsnew, $psacar_car->door_count->CurrentValue, NULL, FALSE);

            // fuel
            $psacar_car->fuel->SetDbValueDef($rsnew, $psacar_car->fuel->CurrentValue, NULL, FALSE);

            // vat
            $psacar_car->vat->SetDbValueDef($rsnew, $psacar_car->vat->CurrentValue, NULL, FALSE);

            // destinations
            $psacar_car->destinations->SetDbValueDef($rsnew, $psacar_car->destinations->CurrentValue, NULL, FALSE);

            // rent_type
            $psacar_car->rent_type->SetDbValueDef($rsnew, $psacar_car->rent_type->CurrentValue, NULL, FALSE);

            // vehicle_type_id
            $psacar_car->vehicle_type_id->SetDbValueDef($rsnew, $psacar_car->vehicle_type_id->CurrentValue, NULL, FALSE);

            // is_driver
            $psacar_car->is_driver->SetDbValueDef($rsnew, $psacar_car->is_driver->CurrentValue, NULL, FALSE);

            // vehicle_id_number
            $psacar_car->vehicle_id_number->SetDbValueDef($rsnew, $psacar_car->vehicle_id_number->CurrentValue, "", FALSE);

            // negotiate
            $psacar_car->negotiate->SetDbValueDef($rsnew, $psacar_car->negotiate->CurrentValue, NULL, FALSE);

            // duration
            $psacar_car->duration->SetDbValueDef($rsnew, $psacar_car->duration->CurrentValue, NULL, FALSE);

            // create_date
            $psacar_car->create_date->SetDbValueDef($rsnew, ew_UnFormatDateTime($psacar_car->create_date->CurrentValue, 5, FALSE), NULL);

            // end_date
            $psacar_car->end_date->SetDbValueDef($rsnew, ew_UnFormatDateTime($psacar_car->end_date->CurrentValue, 5, FALSE), NULL);

            // status
            $psacar_car->status->SetDbValueDef($rsnew, $psacar_car->status->CurrentValue, NULL, TRUE);

            // code
            $psacar_car->code->SetDbValueDef($rsnew, $psacar_car->code->CurrentValue, NULL, FALSE);

            // created_date
            $psacar_car->created_date->SetDbValueDef($rsnew, ew_UnFormatDateTime($psacar_car->created_date->CurrentValue, 5, FALSE), ew_CurrentDate());

            // modified_date
            $psacar_car->modified_date->SetDbValueDef($rsnew, ew_UnFormatDateTime($psacar_car->modified_date->CurrentValue, 5, FALSE), ew_CurrentDate());

            // Call Row Inserting event
            $bInsertRow = $psacar_car->Row_Inserting($rsnew);
            if ($bInsertRow) {                
                $conn->raiseErrorFn = 'ew_ErrorFn';
                $AddRow = $conn->Execute($psacar_car->InsertSQL($rsnew));
                $conn->raiseErrorFn = '';
            } else {
                if ($psacar_car->CancelMessage <> "") {
                    $this->setMessage($psacar_car->CancelMessage);
                    $psacar_car->CancelMessage = "";
                } else {
                    $this->setMessage($Language->Phrase("InsertCancelled"));
                }
                $AddRow = FALSE;
            }

            if ($AddRow) {                
                $psacar_car->id->setDbValue($conn->Insert_ID());
                $rsnew['id'] = $psacar_car->id->DbValue;
                
                // Call Row Inserted event
                $psacar_car->Row_Inserted($rsnew);

                // Image_1
                $rscar_image = array();
                $psacar_car->image_1->Upload->SaveToSession(); // Save file value to Session
                if (is_null($psacar_car->image_1->Upload->Value)) {
                    $rscar_image['image'] = NULL;
                }
                else {
                    $rscar_image['image'] = ew_UploadFileNameEx(
                        ew_UploadPathEx(
                            TRUE, 
                            $psacar_car->image_1->UploadPath), 
                        $psacar_car->image_1->Upload->FileName);
                    
                    $psacar_car_image = new cpsacar_car_image();
                    $psacar_car_image->car_id->SetDbValueDef($rscar_image, $rsnew['id'], 0, FALSE);
                    
                    // Call Row Inserting event
                    $bInsertRow = $psacar_car_image->Row_Inserting($rscar_image);
                    if ($bInsertRow) {
                        if (!ew_Empty($psacar_car->image_1->Upload->Value)) {
                            $psacar_car->image_1->Upload->SaveToFile(
                                $psacar_car->image_1->UploadPath, 
                                $rscar_image['image'], 
                                FALSE);
                        }
                        $conn->raiseErrorFn = 'ew_ErrorFn';
                        $AddRow = $conn->Execute($psacar_car_image->InsertSQL($rscar_image));
                        $conn->raiseErrorFn = '';
                    } 
                    else {
                        if ($psacar_car_image->CancelMessage <> "") {
                            $this->setMessage($psacar_car_image->CancelMessage);
                            $psacar_car_image->CancelMessage = "";
                        } else {
                            $this->setMessage($Language->Phrase("InsertCancelled"));
                        }
                        $AddRow = FALSE;
                    }
                    if ($AddRow) {
                        $psacar_car_image->id->setDbValue($conn->Insert_ID());
                        $rscar_image['id'] = $psacar_car_image->id->DbValue;

                        // Call Row Inserted event
                        $psacar_car_image->Row_Inserted($rscar_image);
                    }                    
                }		                                
                
                // Image_2
                $rscar_image = array();
                $psacar_car->image_2->Upload->SaveToSession(); // Save file value to Session                
                if (is_null($psacar_car->image_2->Upload->Value)) {
                    $rscar_image['image'] = NULL;
                }
                else {
                    $rscar_image['image'] = ew_UploadFileNameEx(
                        ew_UploadPathEx(
                            TRUE, 
                            $psacar_car->image_2->UploadPath), 
                        $psacar_car->image_2->Upload->FileName);
                    
                    $psacar_car_image = new cpsacar_car_image();
                    $psacar_car_image->car_id->SetDbValueDef($rscar_image, $rsnew['id'], 0, FALSE);                
                    
                    // Call Row Inserting event
                    $bInsertRow = $psacar_car_image->Row_Inserting($rscar_image);
                    if ($bInsertRow) {
                        if (!ew_Empty($psacar_car->image_2->Upload->Value)) {
                            $psacar_car->image_2->Upload->SaveToFile(
                                $psacar_car->image_2->UploadPath, 
                                $rscar_image['image'], 
                                FALSE);
                        }
                        $conn->raiseErrorFn = 'ew_ErrorFn';
                        $AddRow = $conn->Execute($psacar_car_image->InsertSQL($rscar_image));
                        $conn->raiseErrorFn = '';
                    } 
                    else {
                        if ($psacar_car_image->CancelMessage <> "") {
                            $this->setMessage($psacar_car_image->CancelMessage);
                            $psacar_car_image->CancelMessage = "";
                        } else {
                            $this->setMessage($Language->Phrase("InsertCancelled"));
                        }
                        $AddRow = FALSE;
                    }
                    if ($AddRow) {
                        $psacar_car_image->id->setDbValue($conn->Insert_ID());
                        $rscar_image['id'] = $psacar_car_image->id->DbValue;

                        // Call Row Inserted event
                        $psacar_car_image->Row_Inserted($rscar_image);
                    }                    
                }
                
                // Image_3
                $rscar_image = array();
                $psacar_car->image_3->Upload->SaveToSession(); // Save file value to Session                
                if (is_null($psacar_car->image_3->Upload->Value)) {
                    $rscar_image['image'] = NULL;
                }
                else {
                    $rscar_image['image'] = ew_UploadFileNameEx(
                        ew_UploadPathEx(
                            TRUE, 
                            $psacar_car->image_3->UploadPath), 
                        $psacar_car->image_1->Upload->FileName);
                    
                    $psacar_car_image = new cpsacar_car_image();
                    $psacar_car_image->car_id->SetDbValueDef($rscar_image, $rsnew['id'], 0, FALSE);                
                    
                    // Call Row Inserting event
                    $bInsertRow = $psacar_car_image->Row_Inserting($rscar_image);
                    if ($bInsertRow) {
                        if (!ew_Empty($psacar_car->image_3->Upload->Value)) {
                            $psacar_car->image_3->Upload->SaveToFile(
                                $psacar_car->image_3->UploadPath, 
                                $rscar_image['image'], 
                                FALSE);
                        }
                        $conn->raiseErrorFn = 'ew_ErrorFn';
                        $AddRow = $conn->Execute($psacar_car_image->InsertSQL($rscar_image));
                        $conn->raiseErrorFn = '';
                    } 
                    else {
                        if ($psacar_car_image->CancelMessage <> "") {
                            $this->setMessage($psacar_car_image->CancelMessage);
                            $psacar_car_image->CancelMessage = "";
                        } else {
                            $this->setMessage($Language->Phrase("InsertCancelled"));
                        }
                        $AddRow = FALSE;
                    }
                    if ($AddRow) {
                        $psacar_car_image->id->setDbValue($conn->Insert_ID());
                        $rscar_image['id'] = $psacar_car_image->id->DbValue;

                        // Call Row Inserted event
                        $psacar_car_image->Row_Inserted($rscar_image);
                    }                    
                }
                
                // Image_4
                $rscar_image = array();
                $psacar_car->image_4->Upload->SaveToSession(); // Save file value to Session                
                if (is_null($psacar_car->image_4->Upload->Value)) {
                    $rscar_image['image'] = NULL;
                }
                else {
                    $rscar_image['image'] = ew_UploadFileNameEx(
                        ew_UploadPathEx(
                            TRUE, 
                            $psacar_car->image_4->UploadPath), 
                        $psacar_car->image_4->Upload->FileName);
                    
                    $psacar_car_image = new cpsacar_car_image();
                    $psacar_car_image->car_id->SetDbValueDef($rscar_image, $rsnew['id'], 0, FALSE);                
                    
                    // Call Row Inserting event
                    $bInsertRow = $psacar_car_image->Row_Inserting($rscar_image);
                    if ($bInsertRow) {
                        if (!ew_Empty($psacar_car->image_4->Upload->Value)) {
                            $psacar_car->image_4->Upload->SaveToFile(
                                $psacar_car->image_4->UploadPath, 
                                $rscar_image['image'], 
                                FALSE);
                        }
                        $conn->raiseErrorFn = 'ew_ErrorFn';
                        $AddRow = $conn->Execute($psacar_car_image->InsertSQL($rscar_image));
                        $conn->raiseErrorFn = '';
                    } 
                    else {
                        if ($psacar_car_image->CancelMessage <> "") {
                            $this->setMessage($psacar_car_image->CancelMessage);
                            $psacar_car_image->CancelMessage = "";
                        } else {
                            $this->setMessage($Language->Phrase("InsertCancelled"));
                        }
                        $AddRow = FALSE;
                    }
                    if ($AddRow) {
                        $psacar_car_image->id->setDbValue($conn->Insert_ID());
                        $rscar_image['id'] = $psacar_car_image->id->DbValue;

                        // Call Row Inserted event
                        $psacar_car_image->Row_Inserted($rscar_image);
                    }                    
                }
                
                // Image_5
                $rscar_image = array();
                $psacar_car->image_5->Upload->SaveToSession(); // Save file value to Session                
                if (is_null($psacar_car->image_5->Upload->Value)) {
                    $rscar_image['image'] = NULL;
                }
                else {
                    $rscar_image['image'] = ew_UploadFileNameEx(
                        ew_UploadPathEx(
                            TRUE, 
                            $psacar_car->image_5->UploadPath), 
                        $psacar_car->image_5->Upload->FileName);
                    
                    $psacar_car_image = new cpsacar_car_image();
                    $psacar_car_image->car_id->SetDbValueDef($rscar_image, $rsnew['id'], 0, FALSE);                
                    
                    // Call Row Inserting event
                    $bInsertRow = $psacar_car_image->Row_Inserting($rscar_image);
                    if ($bInsertRow) {
                        if (!ew_Empty($psacar_car->image_5->Upload->Value)) {
                            $psacar_car->image_5->Upload->SaveToFile(
                                $psacar_car->image_5->UploadPath, 
                                $rscar_image['image'], 
                                FALSE);
                        }
                        $conn->raiseErrorFn = 'ew_ErrorFn';
                        $AddRow = $conn->Execute($psacar_car_image->InsertSQL($rscar_image));
                        $conn->raiseErrorFn = '';
                    } 
                    else {
                        if ($psacar_car_image->CancelMessage <> "") {
                            $this->setMessage($psacar_car_image->CancelMessage);
                            $psacar_car_image->CancelMessage = "";
                        } else {
                            $this->setMessage($Language->Phrase("InsertCancelled"));
                        }
                        $AddRow = FALSE;
                    }
                    if ($AddRow) {
                        $psacar_car_image->id->setDbValue($conn->Insert_ID());
                        $rscar_image['id'] = $psacar_car_image->id->DbValue;

                        // Call Row Inserted event
                        $psacar_car_image->Row_Inserted($rscar_image);
                    }                    
                }
                
                //Reference number
                $sFilterWrk = "id = " . $psacar_car->type_id->CurrentValue;
                $sSqlWrk = "SELECT `short_code` FROM `psacar_car_type`";
                $sWhereWrk = "";
                if ($sFilterWrk <> "") {
                    if ($sWhereWrk <> "") 
                        $sWhereWrk .= " AND ";
                    $sWhereWrk .= "(" . $sFilterWrk . ")";
                }
                if ($sWhereWrk <> "") 
                    $sSqlWrk .= " WHERE " . $sWhereWrk;

                $rswrk = $conn->Execute($sSqlWrk);
                $arwrk = ($rswrk) ? $rswrk->GetRows() : array();
                if ($rswrk) 
                    $rswrk->Close();

                $car_code = '';
                foreach($arwrk as $type)
                    $car_code = $type[0];

                $keys = array_merge(range(0, 9), range('a', 'z', range('A', 'Z')));
                for($counter = 0; $counter < 3; $counter++) {
                    $key .= $keys[array_rand($keys)];
                }
                $car_code .= 
                    substr('00000' . $psacar_car->id->DbValue, -5) . 
                    $key;                    
                $psacar_car->code->SetDbValueDef($rsnew, $car_code, "", FALSE);

                $psacar_car->CurrentFilter = "Id = " . $psacar_car->id->DbValue;
                $conn->raiseErrorFn = 'ew_ErrorFn';
                $EditRow = $conn->Execute($psacar_car->UpdateSQL($rsnew));
                $conn->raiseErrorFn = '';
            }

            // image
            $psacar_car->image_1->Upload->RemoveFromSession(); // Remove file value from Session
            $psacar_car->image_2->Upload->RemoveFromSession(); // Remove file value from Session
            $psacar_car->image_3->Upload->RemoveFromSession(); // Remove file value from Session
            $psacar_car->image_4->Upload->RemoveFromSession(); // Remove file value from Session
            $psacar_car->image_5->Upload->RemoveFromSession(); // Remove file value from Session
            return $AddRow;
        }

	// Page Load event
	function Page_Load() {

		//echo "Page Load";
	}

	// Page Unload event
	function Page_Unload() {

		//echo "Page Unload";
	}

	// Page Redirecting event
	function Page_Redirecting(&$url) {

		// Example:
		//$url = "your URL";

	}

	// Message Showing event
	function Message_Showing(&$msg) {

		// Example:
		//$msg = "your new message";

	}

	// Form Custom Validate event
	function Form_CustomValidate(&$CustomError) {

		// Return error message in CustomError
		return TRUE;
	}
}
?>
